package com.tj.jinzao.fragment;

import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.tj.jinzao.R;
import com.tj.jinzao.activity.CompleteInfoActivity;
import com.tj.jinzao.base.BaseFragment;
import com.tj.jinzao.utils.ToastUtils;
import com.tj.jinzao.widgets.CustomDialog;

import butterknife.BindColor;
import butterknife.BindView;
import butterknife.OnClick;


/**
 * 完善资料2-性别
 * Created by wjy on 2019/1/6.
 */
public class CompleteInfoStep2Fragment extends BaseFragment {

    @BindView(R.id.tv_male)
    TextView mMaleView;
    @BindView(R.id.tv_female)
    TextView mFeMaleView;

    @BindColor(R.color.colorPrimary)
    int mSelectedColor;
    @BindColor(R.color.gray_gender_text)
    int mUnSelectColor;

    private int mGender = 0;

    @Override
    protected void setupViews(LayoutInflater inflater, View view) {
        super.setupViews(inflater, view);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_complete_info_step_2;
    }

    @OnClick(R.id.ll_female_layout)
    public void female() {
        mGender = 2;
        mFeMaleView.setTextColor(mSelectedColor);
        mMaleView.setTextColor(mUnSelectColor);
    }

    @OnClick(R.id.ll_male_layout)
    public void male() {
        mGender = 1;
        mMaleView.setTextColor(mSelectedColor);
        mFeMaleView.setTextColor(mUnSelectColor);
    }

    @OnClick(R.id.bt_next)
    public void next() {
        if (mGender == 0) {
            ToastUtils.showToast(getActivity(),"请选择性别");
            return;
        }
        CustomDialog dialog = new CustomDialog.Builder(mContext).setMessage("性别设定后无法更改，确定吗")
                .setPositiveButton("取消").setNegativeButton("确定").setOnClickListener(new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if(which == DialogInterface.BUTTON_POSITIVE){
                        }else {
                            if (mContext instanceof CompleteInfoActivity) {
                                if (mGender != 0) {
                                    ((CompleteInfoActivity) mContext).setData("gender", mGender);
                                }else {
                                    ToastUtils.showToast(getActivity(),"请选择性别");
                                    return;
                                }
                                ((CompleteInfoActivity) mContext).next();
                            }

                        }
                        dialog.dismiss();
                    }
                }).create();
        dialog.show();

    }

}
